/**
 * 项目虚拟表管理--项目虚拟表列表的单例对象
 */
var ProjectTable = {
    id: "ProjectTableTable",//表格id
    seItem: null,		//选中的第一条记录
    ids: null,//选中的所有记录ids
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ProjectTable.initColumn = function () {
    var columns = [
        {field: 'selectItem'},
        {title: '编号', field: 'id', align: 'center', valign: 'middle', sortable: true},
        {title: '项目名称', field: 'project_name', align: 'center', valign: 'middle', sortable: true},
        {title: '表名', field: 'table_name', align: 'center', valign: 'middle', sortable: true},
        {title: '表功能描述', field: 'table_desc', align: 'center', valign: 'middle', sortable: true}]
    return columns;
};

/**
 * 检查是否选中
 */
ProjectTable.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        ProjectTable.seItem = selected[0];
        var ids = "";
        for (var i = 0; i < selected.length; i++) {
            var item = selected[i];
            ids = ids + item.id + ",";
        }
        ids = ids.substring(0, ids.length - 1);
        ProjectTable.ids = ids;
        return true;
    }
};

/**
 * 点击添加项目虚拟表
 */
ProjectTable.openProjectTable = function () {
    var index = layer.open({
        type: 2,
        title: '新建项目虚拟表',
        area: ['1000px', '800px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/projectTable/project_table_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看项目虚拟表详情
 */
ProjectTable.openProjectTableDetail = function () {
    if (this.check()) {
        if (isNaN(ProjectTable.ids)) {
            Feng.info("请不要选择多条记录！");
            return false;
        }
        var index = layer.open({
            type: 2,
            title: '项目虚拟表详情',
            area: ['1000px', '800px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/projectTable/project_table_update/' + ProjectTable.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 打开查看项目虚拟表详情
 */
ProjectTable.openProjectTableProperty = function () {
    if (this.check()) {
        if (isNaN(ProjectTable.ids)) {
            Feng.info("请不要选择多条记录！");
            return false;
        }
        var index = layer.open({
            type: 2,
            title: '项目虚拟表详情',
            area: ['80%', '800px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/projectTable/table_property_edit/' + ProjectTable.seItem.id
        });
        this.layerIndex = index;
    }
};


$(function () {
    var defaultColunms = ProjectTable.initColumn();
    var table = new BSTable(ProjectTable.id, "/projectTable/list", defaultColunms);
    table.setPaginationType("server");
    ProjectTable.table = table.init();
});